var http = require("../../../utils/httpUtils.js")
var common = require("../../../utils/common.js")
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentData: 0,
    orderData: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '我的订单',
    })
    if (options.current_data) {
      this.setData({
        currentData: options.current_data
      })
    }
    this.getData();
  },
  delOrder: function (e) {
    console.log(e.currentTarget.dataset.o_no)
    var that = this
    wx.showModal({
      title: '提示',
      content: '您确定删除该订单么？',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          var urls = app.globalData.SERVER_IP + "/order/hide_order"
          var params = {
            o_no: e.currentTarget.dataset.o_no
          }
          http.P(urls, params, (resP) => {
            console.log(resP.data)
            that.getData();
          }, (err) => {
            console.log("获取信息失败")
            console.log(err)
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  getData: function () {
    http.G(app.globalData.SERVER_IP + '/order/search_order/o_is_refund/0/o_uid/' + wx.getStorageSync('userInfo').userid + '/skip/0/limit/20', {}, (res) => {
      let informationData = res.result.orderListData
      console.log(informationData);
      this.setData({
        orderData: informationData
      })
    }, (err) => {
      console.log("error:")
      console.log(err)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.hideShareMenu({})
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  bindchange: function (e) {
    const that = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  checkCurrent: function (e) {
    const that = this;
    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentData: e.target.dataset.current
      })
    }
  },
  go_order_detail: function (e) {
    wx.navigateTo({
      url: "/pages/user_center/order_detail/order_detail?o_no=" + e.currentTarget.dataset.o_no
    })
  },
  go_evaluate: function (e) {
    var o_no = e.target.dataset.o_no;
    wx.navigateTo({
      url: "/pages/user_center/order_evaluate/order_evaluate?o_no=" + o_no
    })
  },
  go_pay_order: function (e) {
    var o_no = e.currentTarget.dataset.o_id;
    wx.navigateTo({
      url: '../../activity/pay/checkOrder/checkOrder' + '?ono=' + o_no,
    })
  },
  getExchangeCode: function (e) {

    wx.navigateTo({
      url: "/pages/user_center/order_detail/order_detail?o_no=" + e.currentTarget.dataset.o_no,
    })
  },
  buy_one_more: function (e) {
    var type = e.currentTarget.dataset.type;
    var id = e.currentTarget.dataset.id;
    if (type == 0) {
      wx.navigateTo({
        url: '../../activity/promotion/promotion?activityId=' + id + '&o_id=692',
      })
    } else if (type == 2) {
      wx.navigateTo({
        url: '../../activity/course/course?activityId=' + id + '&o_id=692',
      })
    }
  },
  go_refund: function (e) {
    console.log(e.currentTarget.dataset.oitem)
    var oitem = e.currentTarget.dataset.oitem
    wx.navigateTo({
      url: '../refund_apply_for/refund_apply_for?o_no=' + oitem.o_no + "&o_title=" + oitem.o_course_name + "&o_course_pic=" + oitem.o_course_pic + "&of_refund_cash=" + oitem.o_new_price + "&o_id=" + oitem.o_id,
    })
  }
})